﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Calculator
{
    public class ExpressionParser
    {
        char[] operations = new[] {'+', '-', '*', '/'};

        public Tuple<decimal,decimal> GetOperands(string exp)
        {
            var operands = exp.Split(operations);
            decimal operand1, operand2;
            decimal.TryParse(operands[0], out operand1);
            decimal.TryParse(operands[1], out operand2);

            return Tuple.Create(operand1,operand2);
        }

        internal char GetOperationChar(string exp)
        {
            var index = exp.IndexOfAny(operations);
            return exp.ElementAt(index);
        }

        public Operation GetOperation(string exp)
        {
            switch (GetOperationChar(exp))
            {
                case '+':
                    return Operation.Add;
                case '-':
                    return Operation.Subtract;
                case '*':
                    return Operation.Multiply;
                case '/':
                    return Operation.Divide;
            }
            return Operation.Default;
        }

    }

    

}
